Listing 7-1 shows a simple but complete application program illustrating the use of QuickTime on the Windows platform. The program uses the Windows single document interface (SDI) to present a movie on the screen, allowing the user to control its display by manipulating a standard movie controller with the mouse. The program also supports basic operations such as file saving and simple cut-and-paste editing. The code shown here is adapted from one of the sample programs provided as part of the QuickTime 3 Software Development Kit for Windows.
Listing 7-1 Simple movie player
///////////////////////////////////////////////////////////////////////////////////////
//
// SimpleEditSDI
// Written by Keith Gurganus
//
// A single-document-interface (SDI) application that plays a movie with QuickTime.
// This program is part of the QuickTime sample source code and is provided as is.
//
// Copyright:© 1997 by Apple Computer, Inc., all rights reserved.
//
///////////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <windows.h>
#include "QTML.h"
#include "Movies.h"
/ Resource identifiers
#define IDM_NEW 100
#define IDM_OPEN 101
#define IDM_SAVE 102
#define IDM_SAVEAS 103
#define IDM_PRINT 104
#define IDM_PRINTSETUP 105
#define IDM_EXIT 106
#define IDM_UNDO 200
#define IDM_CUT 201
#define IDM_COPY 202
#define IDM_PASTE 203
#define IDM_LINK 204
#define IDM_LINKS 205
#define IDM_HELPCONTENTS 300
#define IDM_HELPSEARCH 301
#define IDM_HELPHELP 302
#define IDM_ABOUT 303
#define IDM_HELPTOPICS 304
#define IDC_STATIC -1
#define DLG_VERFIRST 400
#define IDC_COMPANY DLG_VERFIRST
#define IDC_FILEDESC DLG_VERFIRST+1
#define IDC_PRODVER DLG_VERFIRST+2
#define IDC_COPYRIGHT DLG_VERFIRST+3
#define IDC_OSVERSION DLG_VERFIRST+4
#define IDC_TRADEMARK DLG_VERFIRST+5
#define DLG_VERLAST DLG_VERFIRST+5
#define IDC_LABEL DLG_VERLAST+1
#define IDR_ACCELSIMPLESDI 128
#define IDR_SIMPLESDI 128
#define IDR_SMALL 129
#define IDR_WIN95 131
#define IDD_ABOUTBOX 132
#define IDI_BIG 139
#define APPNAME 'SimpleEditSDI'
// Macros to determine appropriate code paths
#if defined (WIN32)
#define IS_WIN32 TRUE
#else
#define IS_WIN32 FALSE
#endif
#define IS_NT IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
#define IS_WIN32S IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
#define IS_WIN95 (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
// Data type
typedef struct
{
char filename[255];
Movie theMovie;
MovieController theMC;
Boolean movieOpened;
HWND theHwnd;
} MovieStuff;
// Global variables
HINSTANCE hInst; // Current instance
char szAppName[] = APPNAME; // Name of this application
char szTitle[] = APPNAME; // Title bar text
MovieStuff gMovieStuff; // Movie structure
// Function prototypes
BOOL
InitApplication
(HINSTANCE hInstance);
ATOM
MyRegisterClass
(CONST WNDCLASS *lpwc);
BOOL
InitInstance
(HINSTANCE hInstance,
int nCmdShow);
LRESULT CALLBACK
WndProc
(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
LRESULT CALLBACK
About
(HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam);
BOOL
GetFile
(char *fileName);
static UINT APIENTRY
GenericHook
(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
BOOL
OpenMovie
(HWND hwnd,
MovieStuff *movieStuff);
void
CreateNewMovieController
(HWND hwnd,
Movie theMovie,
MovieController *theMC);
Boolean
MCFilter
(MovieController mc,
short action,
void *params,
long refCon);
void
GetMaxBounds
(Rect *maxRect);
void
SetWindowTitle
(HWND hWnd,
unsigned char *theFullPath);
void
GetFileNameFromFullPath
(unsigned char *theFullPath,
unsigned char *fileName);
void
CloseMovie
(MovieStuff *movieStuff);
OSErr
SaveMovie
(MovieStuff *movieStuff);
OSErr
SaveAsMovie
(MovieStuff *movieStuff);
ComponentResult
EditUndo
(MovieController mc);
ComponentResult
EditCut
(MovieController mc);
ComponentResult
EditCopy
(MovieController mc);
ComponentResult
EditPaste
(MovieController mc);
ComponentResult
EditClear
(MovieController mc);
ComponentResult
EditSelectAll
(Movie movie,
MovieController mc);
void
UpdateMenus
(MovieStuff movieStuff);
///////////////////////////////////////////////////////////////////////////////////////
//
// WinMain
//
///////////////////////////////////////////////////////////////////////////////////////
int CALLBACK
WinMain
(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HANDLE hAccelTable;
if ( !hPrevInstance )
// Perform instance initialization.
if ( !InitApplication(hInstance) )
return FALSE;
// Initialize QuickTime Media Layer.
InitializeQTML(0);
// Initialize QuickTime.
EnterMovies();
// Perform application initialization.
if ( !InitInstance(hInstance, nCmdShow) )
return FALSE;
// Load accelerator table.
hAccelTable = LoadAccelerators (hInstance,
MAKEINTRESOURCE(IDR_ACCELSIMPLESDI));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
if ( !TranslateAccelerator(msg.hwnd, hAccelTable, &msg) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} /* end if */
// Terminate QuickTime.
ExitMovies();
// Terminate QuickTime Media Layer.
TerminateQTML();
return msg.wParam;
// The following line is included to prevent
// 'unused formal parameter' warnings.
lpCmdLine;
} /* end WinMain */
///////////////////////////////////////////////////////////////////////////////////////
//
// InitApplication
//
///////////////////////////////////////////////////////////////////////////////////////
BOOL
InitApplication
(HINSTANCE hInstance)
{
WNDCLASS wc;
HWND hwnd;
// Win32 will always set hPrevInstance to NULL. We only want a single version
// of this app to run at a time, so let's check things a little closer.
hwnd = FindWindow (szAppName, NULL);
if ( hwnd )
// We found another instance of ourself. Let's defer to it:
{
if ( IsIconic(hwnd) )
ShowWindow(hwnd, SW_RESTORE);
SetForegroundWindow (hwnd);
retur
| Previous | Chapter Contents | Chapter Top | Roadmap |